package org.example.scenicspot.persistence;

import org.apache.ibatis.annotations.*;
import org.example.scenicspot.domain.RealtimeInfo;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface realtimeInfoMapper {
    @Select("select realtimeinfo.id,ScenicAreaID,Name,VisitorCount,AvailableParkingSpaces,Timestamp from realtimeinfo,scenicspotmsg where realtimeinfo.ScenicAreaID=scenicspotmsg.id")
    List<RealtimeInfo> selectAll();

    @Select("select realtimeinfo.id,ScenicAreaID,Name,VisitorCount,AvailableParkingSpaces,Timestamp from realtimeinfo,scenicspotmsg where realtimeinfo.ScenicAreaID=scenicspotmsg.id and scenicspotmsg.name LIKE CONCAT('%', #{name}, '%')")
    List<RealtimeInfo> selectByName(String name);

    @Select("select realtimeinfo.id,ScenicAreaID,Name,VisitorCount,AvailableParkingSpaces,Timestamp from realtimeinfo,scenicspotmsg where realtimeinfo.ScenicAreaID=scenicspotmsg.id and realtimeinfo.ScenicAreaID = #{id}")
    RealtimeInfo selectByID(int id);

    @Insert("INSERT INTO realtimeinfo(id,ScenicAreaID,VisitorCount,AvailableParkingSpaces,Timestamp)VALUES (#{id},#{ScenicAreaID},#{VisitorCount},#{AvailableParkingSpaces},#{Timestamp})")
    void insert(int id, int ScenicAreaID, int VisitorCount, int AvailableParkingSpaces, String Timestamp);

    @Delete("DELETE FROM realtimeinfo WHERE realtimeinfo.ScenicAreaID = #{ScenicAreaID}")
    void delete(int ScenicAreaID);

    @Update("UPDATE realtimeinfo set status = #{status} where id = #{id}")
    void update(@Param("status") String status,@Param("id") int id);
}
